import ViewBase from "../../engine/ViewBase";
import { RoomConfig_huanghua_mj } from "../config/RoomConfig_huanghua_mj";
import { UIHelper } from "../util/UIHelper";


const { ccclass, property } = cc._decorator;

@ccclass
export default class ViewRenHuaiPaiSetting extends ViewBase {

    private roomConfig: RoomConfig_huanghua_mj
    private dakuanzhang_toggleContainer: cc.ToggleContainer
    private daduizi_toggleContainer: cc.ToggleContainer
    private qinggang_toggleContainer: cc.ToggleContainer;
    private zimo_toggleContainer: cc.ToggleContainer

    public onInitChild(roomConfig: RoomConfig_huanghua_mj): void {
        this.roomConfig = roomConfig;
     
    }

    onEnable(): void {
        super.onEnable()
        this.zimo_toggleContainer = this.getChild(this.node, "zimo_toggleContainer", cc.ToggleContainer)
        // let zimoIndex: number = RoomConfig_huanghua_mj.zimoConfig.indexOf(this.roomConfig.zimo)
        // this.setToggleContainerIndex(this.zimo_toggleContainer, zimoIndex)
        this.setToggleContainerIndex(this.zimo_toggleContainer, this.roomConfig.zimo)

        this.dakuanzhang_toggleContainer = this.getChild(this.node, "dakuanzhang_toggleContainer", cc.ToggleContainer)
        // let dakuanzhangIndex: number = RoomConfig_huanghua_mj.dakuanzhangConfig.indexOf(this.roomConfig.dakuanzhang)
        // this.setToggleContainerIndex(this.dakuanzhang_toggleContainer, dakuanzhangIndex)
        this.setToggleContainerIndex(this.dakuanzhang_toggleContainer, this.roomConfig.dakuanzhang)
        this.daduizi_toggleContainer = this.getChild(this.node, "daduizi_toggleContainer", cc.ToggleContainer)
        // let daduiziIndex: number = RoomConfig_huanghua_mj.daduiziConfig.indexOf(this.roomConfig.daduizi)
        // this.setToggleContainerIndex(this.daduizi_toggleContainer, daduiziIndex)
        this.setToggleContainerIndex(this.daduizi_toggleContainer, this.roomConfig.daduizi)

        this.qinggang_toggleContainer = this.getChild(this.node, "qinggang_toggleContainer", cc.ToggleContainer)
        // let qianggangIndex: number = RoomConfig_huanghua_mj.qingGangConfig.indexOf(this.roomConfig.daduizi)
        // this.setToggleContainerIndex(this.qinggang_toggleContainer, qianggangIndex)
        this.setToggleContainerIndex(this.qinggang_toggleContainer, this.roomConfig.qinggang)

        for (let i = 0; i < RoomConfig_huanghua_mj.dakuanzhangConfig.length; i++) {
            let txtInfo: cc.Label = this.getChild(this.dakuanzhang_toggleContainer.node, "txtInfo" + i, cc.Label)
            txtInfo.string = RoomConfig_huanghua_mj.dakuanzhangConfig[i] + "+"
        }
        for (let i = 0; i < RoomConfig_huanghua_mj.daduiziConfig.length; i++) {
            let txtInfo: cc.Label = this.getChild(this.daduizi_toggleContainer.node, "txtInfo" + i, cc.Label)
            txtInfo.string = RoomConfig_huanghua_mj.daduiziConfig[i] + "+"
        }

        for (let i = 0; i < RoomConfig_huanghua_mj.qingGangConfig.length; i++) {
            let txtInfo: cc.Label = this.getChild(this.qinggang_toggleContainer.node, "txtInfo" + i, cc.Label)
            txtInfo.string = RoomConfig_huanghua_mj.qingGangConfig[i] + "+"
        }


        let btnqueding: cc.Node = this.findChild(this.node, "btnqueding")
        UIHelper.onAddEvent(btnqueding, () => {
            this.closeView()
            this.roomConfig.dakuanzhang = this.getToggleContainerIndex(this.dakuanzhang_toggleContainer)
            this.roomConfig.daduizi = this.getToggleContainerIndex(this.daduizi_toggleContainer)
            this.roomConfig.qinggang = this.getToggleContainerIndex(this.qinggang_toggleContainer)
            this.roomConfig.zimo = this.getToggleContainerIndex(this.zimo_toggleContainer)
        })
    }

}
